# -*- coding: utf-8 -*-
"""
------------------------------------------------------------------------------
    File Name:  random
    Author   :  wanwei1029
    Date     :  2018/10/9
    Desc     :常用随机数的使用方法
------------------------------------------------------------------------------
"""
import random as rd
import samp.samp_logging as sl

logger = sl.get_logger('random_demo')


def base_random():
    """
    random.random() 用于生成一个0到1的随机符点数: 0 <= n < 1.0
    random.uniform(a, b)，用于生成一个指定范围内的随机符点数，两个参数其中一个是上限，一个是下限
    random.randint(a, b)，用于生成一个指定范围内的整数
    random.shuffle 用于将一个列表中的元素打乱,注意，这个是在原数组上打乱，返回值是None
    :return:
    """
    logger.info("random.random value : {0}".format(rd.random()))
    logger.info("random.uniform value : {0}".format(rd.uniform(1, 20)))
    logger.info("random.uniform value : {0}".format(rd.uniform(-1, -20)))
    logger.info("random.randint value : {0}".format(rd.randint(1, 20)))
    a = list(range(1, 10))
    logger.info("range(1, 10) value : {0}".format(a))
    rd.shuffle(a)
    logger.info("rd.shuffle(a) value : {0}".format(a))


def shuffle():
    a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
    rd.shuffle(a)
    print(a)


def sample():
    a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
    b = rd.sample(a, 3)
    print(b)


if __name__ == '__main__':
    test_method = "sample"
    if test_method == "base_random":
        base_random()
    elif test_method == "shuffle":
        shuffle()
    elif test_method == "sample":
        sample()
